/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Grafik;

import ModulHåndtering.Modul;
import ModulHåndtering.Sensor;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.util.ArrayList;

/**
 *
 * @author Thor
 */
public class GrafTegning extends javax.swing.JPanel {

    Oversigt ejer;
    private Modul modul;
    private final ArrayList<Color> colors = new ArrayList<>();

    public void setEjer(Oversigt ejer) {
        this.ejer = ejer;
    }

    public void setModul(Modul modul) {
        this.modul = modul;
    }

    /**
     * Creates new form GrafTegning
     */
    public GrafTegning() {
        initComponents();
        colors.add(Color.BLUE);
        colors.add(Color.RED);
        colors.add(Color.GREEN);
        colors.add(Color.ORANGE);
        colors.add(Color.YELLOW);
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator4 = new javax.swing.JSeparator();
        jSeparator5 = new javax.swing.JSeparator();
        jSeparator6 = new javax.swing.JSeparator();

        setBackground(new java.awt.Color(255, 255, 255));
        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 153, 153), 3));
        setMaximumSize(new java.awt.Dimension(350, 210));
        setMinimumSize(new java.awt.Dimension(350, 210));
        setLayout(null);
        add(jSeparator1);
        jSeparator1.setBounds(3, 256, 394, 10);

        jLabel1.setText("1 min");
        add(jLabel1);
        jLabel1.setBounds(330, 270, 40, 16);

        jLabel2.setText("2 min");
        add(jLabel2);
        jLabel2.setBounds(240, 270, 50, 16);

        jLabel3.setText("3 min");
        add(jLabel3);
        jLabel3.setBounds(140, 270, 40, 16);

        jLabel4.setText("4 min");
        jLabel4.setPreferredSize(new java.awt.Dimension(55, 14));
        add(jLabel4);
        jLabel4.setBounds(40, 270, 40, 14);

        jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);
        add(jSeparator3);
        jSeparator3.setBounds(50, 0, 10, 257);

        jSeparator4.setOrientation(javax.swing.SwingConstants.VERTICAL);
        add(jSeparator4);
        jSeparator4.setBounds(340, 0, 10, 257);

        jSeparator5.setOrientation(javax.swing.SwingConstants.VERTICAL);
        add(jSeparator5);
        jSeparator5.setBounds(250, 0, 10, 257);

        jSeparator6.setOrientation(javax.swing.SwingConstants.VERTICAL);
        add(jSeparator6);
        jSeparator6.setBounds(150, 0, 10, 257);
    }// </editor-fold>//GEN-END:initComponents

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;//Brug grafics 2d
        /*Sæt tegnevink til trappeudjevning (antialiasing)*/
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        ArrayList<Point> grafPunkter;

        ArrayList<Sensor> sensorList = modul.sensorList;

        int color;
        for (Sensor sensor : sensorList) {
            grafPunkter = sensor.grafPunkter();
            for (int i = 0; i < (grafPunkter.size() - 1); i++) {
                g2.setColor(colors.get(sensorList.indexOf(sensor)));
                //Opret x og y for startpunktet
                int x1 = grafPunkter.get(i).x;
                int y1 = (this.getHeight() - grafPunkter.get(i).y) - 50;
                //Opret x og y for slutpunktet
                int x2 = grafPunkter.get(i + 1).x;
                int y2 = (this.getHeight() - grafPunkter.get(i + 1).y) - 50;
                //Tegn en linje fra start til slut
                g2.drawLine(x1, y1, x2, y2);
            }
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    // End of variables declaration//GEN-END:variables
}
